Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 多列书签
- // @include main
- // ==/UserScript==
- location.href.startsWith('chrome://browser/content/browser.x') && (() => {
- //按顺序从两列开始
- const column = [
- ['2列显示的书签文件夹名称1', '2列名称2', '2列名称3', '2列名称4'],
- ['3列显示的书签文件夹名称1', '3列名称2'],
- ['4列显示的书签文件夹名称1', '4列名称2'],
- //...由此类推
- ];
- const BOOKMARK_WIDTH = 180; // 书签宽度
- const MARGIN_RIGHT = 5;
- const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
- sss.loadAndRegisterSheet(Services.io.newURI("data:text/css," + encodeURIComponent(`
- @-moz-document url("chrome://browser/content/browser.xhtml"){
- #PlacesToolbarItems menuitem.bookmark-item .menu-accel-container {
- display: none !important;
- }
- ${column.map(c => {
- return c.length ? `#PlacesToolbarItems .bookmark-item[container="true"]:is(
- ${c.map(i => `[label=${JSON.stringify(i)}]`).join(', ')}
- ) > menupopup > :is(menuitem, menu, menuseparator) {
- min-width: ${BOOKMARK_WIDTH}px !important;
- max-width: ${BOOKMARK_WIDTH}px !important;
- margin-right: ${MARGIN_RIGHT}px !important;
- }` : '';
- }).join('\n')}
- }`), null, null), sss.USER_SHEET);
- function _getScrollableElements () {
- let nodes = this.children;
- if(nodes.length == 1 && nodes[0].className === 'scrollbox-innerbox') {
- nodes = nodes[0].children;
- }
- if (nodes.length == 1) {
- let node = nodes[0];
- if (node.localName == 'children' &&
- node.namespaceURI == 'http://www.mozilla.org/xbl') {
- nodes = document.getBindingParent(this).children;
- } else if (node.localName == 'slot' &&
- node.namespaceURI == 'http://www.w3.org/1999/xhtml') {
- nodes = node.getRootNode().host.children;
- }
- }
- return Array.prototype.filter.call(nodes, this._canScrollToElement, this);
- }
- const PlacesToolbarItems = document.getElementById('PlacesToolbarItems');
- PlacesToolbarItems.addEventListener('popupshowing', (event) => {
- const menupopup = event.target;
- if(menupopup._isInitMultipledBM) return;
- const title = menupopup.parentNode &&
- menupopup.parentNode._placesNode &&
- menupopup.parentNode._placesNode.title;
- menupopup._isInitMultipledBM = true;
- let col = -1;
- if(!title || !menupopup.shadowRoot || (col = column.findIndex(c => {
- return c.indexOf(title) > -1;
- })) === -1) return;
- col += 2;
- const markup = `<html:style>
- arrowscrollbox::part(scrollbox), /*bug 1514926*/
- scrollbox.arrowscrollbox-scrollbox{
- overflow-y: auto !important;
- }
- arrowscrollbox > .scrollbox-innerbox{
- display:grid !important;
- grid-template-columns: repeat(${col}, 1fr);
- }
- </html:style>${menupopup.markup.replace(
- /<html:slot\/>|<html:slot><\/html:slot>/,
- '<box class="scrollbox-innerbox" orient="vertical" pack="start" smoothscroll="false" flex="1">$&</box>'
- )}`;
- let count = menupopup.shadowRoot.childElementCount;
- menupopup.shadowRoot.prepend(MozXULElement.parseXULToFragment(markup));
- while(count--) menupopup.shadowRoot.lastElementChild.remove();
- const arrowscrollbox = menupopup.shadowRoot.querySelector('arrowscrollbox');
- if(arrowscrollbox && arrowscrollbox._getScrollableElements) {
- arrowscrollbox._getScrollableElements = _getScrollableElements.bind(arrowscrollbox);
- }
- if(menupopup.__indicatorBar){
- menupopup.__indicatorBar = null;
- menupopup._scrollBox = null;
- }else{
- menupopup._indicatorBar = menupopup.shadowRoot.querySelector(
- '[part="drop-indicator-bar"]'
- );
- menupopup._scrollBox = menupopup.shadowRoot.querySelector(
- 'arrowscrollbox'
- );
- }
- }, true);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement